package com.llc.spring.cloud.sdk.core.ex;

import com.alibaba.fastjson.JSON;
import com.llc.spring.cloud.sdk.core.http.Result;

/**
 * time 2018/8/27 9:45
 *
 * @author xiaojie.zhu <br>
 */
public class RequestException extends RuntimeException {
    private int code;

    public RequestException(int code) {
        this.code = code;
    }

    public RequestException(String message, int code) {
        super(message);
        this.code = code;
    }

    public RequestException(String message, Throwable cause, int code) {
        super(message, cause);
        this.code = code;
    }

    public RequestException(Throwable cause, int code) {
        super(cause);
        this.code = code;
    }

    public RequestException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, int code) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
    }

    @Override
    public String getMessage() {
        Result result = new Result();
        result.setCode(this.code);
        result.setMsg(super.getMessage());
        String s = JSON.toJSONString(result);
        return s;

    }
}
